const SMSClient = require('@alicloud/sms-sdk');
const smsConfig = require('../../../config/sms.json');

let smsClient = null;

/**
 * @returns {SMSClient}
 */
function getSmsClient () {
    if (!smsClient) {
        const accessKeyId = smsConfig.akId;
        const secretAccessKey = smsConfig.akSecret;
        smsClient = new SMSClient({ accessKeyId, secretAccessKey });
    }
    return smsClient;
}

async function sendRecruitmentSMS (phone, templateData) {
    await getSmsClient().sendSMS({
        PhoneNumbers: phone,
        SignName: smsConfig.smsSignName,
        TemplateCode: smsConfig.templateCode,
        TemplateParam: JSON.stringify(templateData)
    });
}
module.exports = {
    sendRecruitmentSMS
};
